package cn.yunhe.servlet;

import cn.yunhe.bean.Scenery;
import cn.yunhe.bean.Travel;
import cn.yunhe.biz.TravelService;
import cn.yunhe.util.DateUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/TravelAddServlet")
public class TravelAddServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {



        String topic=request.getParameter("topic");
        String traSeason=request.getParameter("tra_season");
        int traDay=Integer.parseInt(request.getParameter("tra_days"));
        int price=Integer.parseInt(request.getParameter("price"));
        String playType=request.getParameter("play_type");
        String location=request.getParameter("location");
        String pubTime=DateUtil.getNowTime();
        int sceid=Integer.parseInt(request.getParameter("sceid"));
        Scenery sce=new Scenery();
        sce.setSceId(sceid);
        String context=request.getParameter("context");
        String pic=request.getParameter("pic");

        Travel travel=new Travel(topic,traSeason,traDay,price,playType,location,sce,context,pic,pubTime);

        TravelService travelService=new TravelService();

        int flag=travelService.addTravel(travel);
        if(flag>0){
            response.sendRedirect("travelNote.jsp");
        }else{
            response.sendRedirect("singleTravel.jsp");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);

    }
}
